package com.hyfrogx.modules.attention.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyfrogx.common.exception.ServiceException;
import com.hyfrogx.common.utils.QueryExt;
import com.hyfrogx.common.utils.R;
import com.hyfrogx.modules.app.annotation.Login;
import com.hyfrogx.modules.app.entity.HyUserAttentionEntity;
import com.hyfrogx.modules.app.service.AttentionService;
import com.hyfrogx.modules.manage.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;


/**
 * 我的关注
 *
 * @项目 hyplatform2.0
 * @日期: 2017年9月13日
 * @负责人: xjM
 */
@RestController
@RequestMapping("attention")
@Api(value = "AttentionController", tags = {"后台--关注模块"})
public class AttentionController extends BaseController {

  @Autowired
  private AttentionService attentionService;

  /**
   * 被关注，获取粉丝列表
   *
   * @return
   */
  @GetMapping(value = "getpage")
  @Login
  @ApiOperation("被关注，获取粉丝列表")
  public R getpage(@ApiIgnore @RequestAttribute("userId") Long userId,@RequestParam Map<String, Object> map) {
    try {
      //判断数据库内是否存在该用户信息，如果没有返回null，反之查询用户粉丝信息
      HyUserAttentionEntity attSuns = attentionService.getBaseMapper()
        .selectOne(new QueryWrapper<HyUserAttentionEntity>().eq("sid",userId));
      if (attSuns == null) {
        Integer status = 0;
        return R.ok().put("data",status);
      } else {

        //Integer bothtype=1;
        Page page = attentionService.getAllFunsId(new QueryExt<>(map));
        List<HyUserAttentionEntity> result = page.getRecords();
				/*User fsInfo=null;
				for (HyUserAttention fs : attention) {
					Integer fsid = fs.getFid();
					fsInfo = userService.findUserById(fsid);
					fs.setUser(fsInfo);
				}
				 HashMap<Object,Object> map = new HashMap<>();
				 map.put("attention", attention);*/
        return R.ok().put("data",page);
      }
    } catch (ServiceException e) {
      return R.error(e.getMessage());
    }
  }

  /**
   * 关注，获取我的关注主播列表
   *
   * @return
   */
  @GetMapping(value = "getSelfpage")
  @Login
  @ApiOperation("关注，获取我的关注主播列表")
  public R getSelfpage(@ApiIgnore @RequestAttribute("userId") Long userId,@RequestParam Map<String, Object> map) {

    try {
      HyUserAttentionEntity funs = attentionService.getByFid(userId.intValue());
      if (funs == null) {
        Integer status = 0;
        return R.ok().put("data",status);
      } else {

        map.put("sid",userId);
        Page page = attentionService.getAllSunSid(new QueryExt(map));
        List<HyUserAttentionEntity> result = page.getRecords();
			/*User sInfo=null;
			for (HyUserAttention fs : attention) {
				Integer sid = fs.getSid();//偶像id
				sInfo = userService.findUserById(sid);
			}*/
			/* HashMap<Object,Object> map = new HashMap<>();
			 map.put("sInfo", sInfo);*/
        return R.ok().put("data",page);
      }
    } catch (ServiceException e) {
      return R.error(e.getMessage());
    }
  }
}
	
